extends ../layout

block css
    link(rel='stylesheet', href='/css/base/ck_base.css', media='screen')
    link(rel='stylesheet', href='/css/user/ck_user2.css', media='screen')
    link(rel='stylesheet', href='/css/modules/page.css')

block content
  .pageContainer.pt20.mb20
    #studentMenu.pageSidebar
      .wsxx
        .hd
          dl
            dt(clas='pic')
              a(href='#', target='_blank')
                img(width='40', height='40', title='背后灵16', src='/images/0-0.JPG')
            dd
              .name
                a.c_666(href='#', target='_blank') 背后灵16
              .set
                a(href='#', target='_blank') 设置
        .bd
          ul.list
              li.wsxx_2.myCourse
                a.myCourse(href='/user/course') 我的课程
              li.wsxx_4.myTask
                a.myTask(href='/user/work') 我的作业
              li.wsxx_5.myTest
                a.myTest(href='/user/quiz') 我的测验
              li.wsxx_12.curr
                a(href='/user/note') 我的笔记
              li.wsxx_13
                a(href='/user/question') 我的问答
              li.wsxx_9
                a(href='/user/order') 我的订单
              li.wsxx_10.myRefund
                a(href='/user/apply') 退款管理
      // =E wsxx 侧边导航
    .pageContent
      .myNote-wrap(style='margin-bottom: 20px;')
        header.note-header.clearfix
          .ico-good
          .right-part
            .c_555.fb.pt5 
            .mt10.f12.c_777
              | 你记录了 
              i.num #{list.length}
              |  篇笔记，
              | 继续加油哦！
        ul.note-list
          if list
            each val , index in list
              li(id='note_li_#{val.id}')
                .date-time
                  p #{val.hour}
                  p.f14
                    i.t_b #{val.month}
                    | /#{val.date}
                if index % 2
                  .note-main.type-sj
                    .note-detail
                      span(id='note_span_#{val.id}')
                        i.t-r #{val.content}
                    .note-bot.clearfix
                      .fl
                        span.b-1 课程： #{val.course} 
                        span.b-2 章节： #{val.chapter}
                      .ed-box
                        a.note-edit(href="javascript:showNoteBox(#{val.id},'edit');")
                          i
                          | 编辑
                        a.note-del(href="javascript:showNoteBox(#{val.id},'del');")
                          i
                          | 删除                    
                else
                  .note-main
                    .note-detail
                      span(id='note_span_#{val.id}')
                        i.t-r #{val.content}
                    .note-bot.clearfix
                      .fl
                        span.b-1 课程： #{val.course} 
                        span.b-2 章节： #{val.chapter}
                      .ed-box
                        a.note-edit(href="javascript:showNoteBox(#{val.id},'edit');")
                          i
                          | 编辑
                        a.note-del(href="javascript:showNoteBox(#{val.id},'del');")
                          i
                          | 删除
                s.clear
              li(id='note_edit_li_#{val.id}',style='display:none;')
                .date-time
                .note-main
                  textarea.note_eidt_input(id='note_edit_#{val.id}',maxlength='500') #{val.content}
                  .tc.mt10
                    a.n_btn30g.mr15(href='javascript:noteOpr(#{val.id},2);') 确定
                    a.n_btn30gr_b(href='javascript:closeNoteBox(#{val.id},2);') 取消
                s.clear
          include ../common/page.jade
      // =E pageContent
    s.clearfix
  script.
    $('.pageNum').hide();
    function showNoteBox(noteid, type) {
    if (type == 'del') {
    closeNoteBox(noteid, 2);
    var boxID = '#note_li_' + noteid;
    var noteMain = '#note_li_' + noteid + '> .note-main > .note-bot';
    var dialog = '#note_li_' + noteid + '> .note-main > .note-del-dialog';
    html = '<div class="note-del-dialog" style="display:none"><div class="d-con"><div class="tc mt15">';
    html += '<img class="mr5" src="/images/ico_warning_24x24.png" alt=""/>';
    html += '<span class="c_fff">删除此条笔记？</span></div>';
    html += '<div class="tc mt10">';
    html += '<a href="javascript:noteOpr(' + noteid + ',1);" class="n_btn30gr_b mr15">删除</a>';
    html += '<a href="javascript:closeNoteBox(' + noteid + ',1);" class="n_btn30gr_b">取消</a></div></div></div>';
    $(noteMain).after(html);
    $(boxID).addClass('del-li');
    $(dialog).show();
    } else if (type == 'edit') {
    var boxID = '#note_edit_li_' + noteid;
    $(boxID).show();
    }
    }
    function noteOpr(noteid, typeid) {
    if (typeid == 1) {
    var note_li = '#note_li_' + noteid;
    var url = "/user/note/del";
    $.ajax({
    url: url,
    type: "POST",
    data: {noteid: noteid},
    async: false,
    dataType: "json",
    success: function (rs) {
    if (rs.code == 0) {
    $(note_li).remove();
    }
    }
    });
    } else if (typeid == 2) {
    //定义元素ID
    var note_li = '#note_li_' + noteid + ' > .note-main';
    var note_edit_li = '#note_edit_li_' + noteid;
    var note_edit = '#note_edit_' + noteid;
    var note_span = '#note_span_' + noteid;
    //获取编辑文本
    var edit_note = String($(note_edit).val());
    var span_note = String($(note_span).text());
    //span_note = span_note.replace(/ \\[速记\] /ig, "");
    if (edit_note != span_note) {
    var url = "/user/note/edit";
    $.ajax({
    url: url,
    type: "POST",
    data: {noteid: noteid, note: edit_note},
    async: false,
    dataType: "json",
    success: function (rs) {
    if (rs.code == 0) {
    $(note_li).removeClass('type-sj');
    $(note_edit_li).hide();
    $(note_span).text(edit_note);
    }
    }
    });
    } else {
    $(note_edit_li).hide();
    }
    }
    }
    function jumpToVideo(sid, courseid, cid, segment, timer) {
    if (sid > 0 && courseid > 0 && cid > 0) {
    url = 'http://www.chuanke.com/v' + sid + '-' + courseid + '-' + cid + '.html?segment=' + segment + '&timer=' + timer;
    window.open(url);
    }
    }
    function closeNoteBox(noteid, typeid) {
    if (typeid == 1) {
    var boxID = '#note_li_' + noteid;
    var dialog = '#note_li_' + noteid + '> .note-main > .note-del-dialog';
    $(dialog).remove();
    $(boxID).removeClass('del-li');
    } else if (typeid == 2) {
    var boxID = '#note_edit_li_' + noteid;
    var note_edit = '#note_edit_' + noteid;
    var note_span = '#note_span_' + noteid;
    $(boxID).hide();
    $(note_edit).val($(note_span).text());
    }
    }
